import { ForwardedRef, useRef } from 'react'

export const useCombineRef = <T>(ref: ForwardedRef<T>) => {
	const innerRef = useRef<T | null>(null)
	const combineRef = (node: T | null) => {
		innerRef.current = node
		if (typeof ref === 'function') ref(node)
		else if (ref?.current) ref.current = node
	}
	return { innerRef, combineRef }
}
